from pages.basePage4 import BasePage
from config.setting import host_port
from selenium.webdriver.common.action_chains import ActionChains
import time

class Userpage(BasePage):
    def __init__(self):
       BasePage.__init__(self)
       time.sleep(2)
       self.driver.get(f"http://{host_port}/SharedParkingPlace/admin/index.html")

    # 定位物业方
    def proper_user(self):
       return self.driver.find_element_by_id('_easyui_tree_11')

    # 定位表单
    def iframe(self):
       return self.driver.find_element_by_id('testIframe')
    # 定位增加
    def add(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[1]/span')

    # 定位删除
    def del_veh(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[2]/span')

    # 定位修改
    def mondfiy_user(self):
        return self.driver.find_element_by_xpath('//div[@id="tb"]/a[3]/span')

    # 定位物业名
    def name(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input1"]')
    #定位联系电话
    def phone(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input2"]')
    # 定位物业简介
    def introduce(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input3"]')
    # 定位证书
    def certificate(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input4"]')
    # 密码
    def psw(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input5"]')

    # 定位新增确定
    def confirm(self):
        return self.driver.find_element_by_xpath('//div[@id="dlg-buttons"]/a[1]')
    # 定位修改确定
    def mconfirm(self):
        return self.driver.find_element_by_xpath('//div[@id="dlg-buttons"]/a[2]')
    #定位查询条件
    def query(self):
        return self.driver.find_element_by_class_name('textbox easyui-fluid searchbox')

    # 定位输入框
    def input_query(self):
        return self.driver.find_element_by_xpath('//input[@id="_easyui_textbox_input6"]')
    # 定位查询按钮
    def clk_query(self):
        return self.driver.find_element_by_xpath('//*[@id="tb"]/span/span/a')
    #定位第一行姓名
    def fist_name(self):
        return self.driver.find_element_by_xpath('//*[@id="datagrid-row-r1-2-0"]/td[2]/div')
    # 勾选框
    def Check(self):
        return self.driver.find_element_by_xpath('/html/body/div[1]/div[2]/div[2]/div[2]/div[2]/table/tbody/tr[1]')


# 操作层
class UserHandle(Userpage):
    def __init__(self):
        Userpage.__init__(self)
    # 点击物业方
    def clk_proper_user(self):
        self.proper_user().click()
    # 表单切换
    def swith_frame(self):
        a = self.iframe()
        return self.driver.switch_to.frame(a)
    # 点击新增
    def clk_add(self):
        self.add().click()
    # 点击删除
    def clk_del(self):
        self.del_veh().click()
    # 点击修改
    def clk_mondfiy(self):
        self.mondfiy_user().click()
    # 输入物业名
    def send_name(self,name):
        input1 = self.name()
        input1.clear()
        input1.send_keys(name)
    # 输入联系电话
    def send_tel(self,phone):
        input2 = self.phone()
        input2.clear()
        input2.send_keys(phone)
    #输入物业简介
    def send_introduce(self,introduce):
        input3 = self.introduce()
        input3.clear()
        input3.send_keys(introduce)
    # 输入证书
    def send_certificate(self,certificate):
        input4 = self.certificate()
        input4.clear()
        input4.send_keys(certificate)
    # 输入密码
    def send_psw(self,psw):
        input5 = self.psw()
        input5.clear()
        input5.send_keys(psw)
    # 点击确定
    def clk_confirm(self):
        self.confirm().click()
    def clk_mconfirm(self):
        self.mconfirm().click()
    # 输入查询内容
    def send_query(self,name1):
        self.input_query().send_keys(name1)
#     点击查询
    def aclk_query(self):
        self.clk_query().click()

    # 勾选框选择
    def click_check(self):
        self.Check().click()
#   获取查询的姓名
    def get_name(self):
        queryname = self.fist_name().text
        return queryname


class UserBusiness(UserHandle):
    def __init__(self):
        UserHandle.__init__(self)
    # 新增
    def new_add(self,name,phone,introduce,certificate,psw):
        """

        :param name: 物业名
        :param phone: 电话
        :param introduce: 简介
        :param certificate: 证书
        :param psw: 密码
        :return:
        """
        self.clk_proper_user()
        self.swith_frame()
        time.sleep(2)
        self.clk_add()
        self.send_name(name)
        self.send_tel(phone)
        self.send_introduce(introduce)
        self.send_certificate(certificate)
        self.send_psw(psw)
        self.clk_confirm()
        self.send_query(name)
        self.aclk_query()
        time.sleep(2)
        return self.get_name()

    def mondfiy_add(self, name, phone, introduce, certificate, psw):
        """
        :param name: 物业名
        :param phone: 电话
        :param introduce: 简介
        :param certificate: 证书
        :param psw: 密码
        :return:
        """
        self.clk_proper_user()
        self.swith_frame()
        time.sleep(2)
        self.click_check()
        self.clk_mondfiy()
        self.send_name(name)
        self.send_tel(phone)
        self.send_introduce(introduce)
        self.send_certificate(certificate)
        self.send_psw(psw)
        self.clk_mconfirm()
        self.send_query(name)
        self.aclk_query()
        time.sleep(2)
        return self.get_name()
if __name__ == '__main__':
    n=UserBusiness()
    r=n.new_add('照哥',119,'蜗牛',147852369,123456)
    print(r)